package com.jiamao.goplay.ui.photo.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.jiamao.goplay.BR;
import com.jiamao.goplay.R;
import com.jiamao.goplay.data.DataRepository;
import com.jiamao.goplay.ui.discover.SearchFragment;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.tatarka.bindingcollectionadapter2.ItemBinding;
import me.tatarka.bindingcollectionadapter2.OnItemBind;

public class PhotoViewVM extends BaseViewModel<DataRepository> {


    public PhotoViewVM(@NonNull Application application, DataRepository repository) {
        super(application, repository);
        //模拟10个条目，数据源可以来自网络
    //    for (int i = 0; i < 20; i++) {

//             PhotoViewItmeVM item = new PhotoViewItmeVM(this);
//                observableList.add(item);

    //    }

    }


    //条目的点击事件
    public BindingCommand seatchCommd = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });


    //给RecyclerView添加ObservableList
    public ObservableList<MultiItemViewModel> observableList = new ObservableArrayList<>();
    //RecyclerView多布局添加ItemBinding
    public ItemBinding<MultiItemViewModel> itemBinding = ItemBinding.of(new OnItemBind<MultiItemViewModel>() {
        @Override
        public void onItemBind(ItemBinding itemBinding, int position, MultiItemViewModel item) {
            //通过item的类型, 动态设置Item加载的布局
            String itemType = (String) item.getItemType();

            itemBinding.set(BR.viewModel, R.layout.photo_view_item_layout);

        }
    });



    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
